package aima.search;

import java.lang.*;
import java.util.*;

/**
   This class extends SearchNode to include initial computation,
   storage, and retrieval of heuristic information.
*/

public class HeuristicSearchNode extends SearchNode {

/**
   Value of heuristic for search node;
*/
   protected float h;

/**
    No-argument constructor needed for Class.newInstance();
*/
   public HeuristicSearchNode() { }

/**
   Constructor makes search node for startState and computes and
   stores heuristic.
*/
   public HeuristicSearchNode(State startState) {
      super(startState);

      computeH();
   }

/**
   Computes and stores heuristic function for state. 
*/
   protected void computeH() {
      h = ((Heuristic)state).h();
   }

/**
  Returns value of heuristic function.
*/
   public float getH() {
      return h;
   }

/**
  Returns f(node), defined as heuristic + cost to node.
*/
   public float getF() {
      return pathCost+h;
   }

/**
   Returns a new node based on a successor of this node.
*/
   public SearchNode makeNode(Successor successor) {
        HeuristicSearchNode node 
           = (HeuristicSearchNode) super.makeNode(successor);

        node.computeH();

        return node;
  } 
}
